package cn.wx.scholar.core.service.async;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wx.common.utils.JSONUtils;
import cn.wx.scholar.core.service.PaperService;

@Service
@Transactional
public class AsyncTxtDataFos {
	
	@Autowired
	private PaperService paperService;
	
	@Async
	public void txtDataFos(List<String> foses) {
		
		if(foses == null || foses.size() == 0) {
			return;
		}
		
		Set<String> set = new HashSet<>();

		for(String fo : foses) {
			
			/**
			 * 判断当前领域是否在数据库中
			 */
			List<String> list = JSONUtils.pa(fo, String.class);

			
			for(String f : list) {
				
				/**
				 * 查看数据中是否有
				 */
				Integer c = paperService.queryOneFos(f);
				/**
				 * 存在放回
				 */
				if(c > 0) {
					continue;
				}
				
				/**
				 * 放入带插入数据库集合
				 */
				set.add(f);
			}
		}
		
		if(set.size() > 0) {
			paperService.createPaperFos(new ArrayList<>(set));
		}
		
	}
	
}
